<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.qijia.travel.app.*"  %>
<%@ page import="com.qijia.travel.domain.*"  %>
<%@ page import="com.qijia.travel.vo.*"  %>
<%@page import="com.qijia.travel.helper.ObjectHelper"%>
<%@page import="java.math.BigDecimal"%>
<%@page import="com.qijia.travel.helper.DateHelper"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setCharacterEncoding("UTF-8");
EptManager manager = new EptManager();
TouristDetailVo vo = (TouristDetailVo)ObjectHelper.ConvertURLRequsetMapToObj(request.getParameterMap(),TouristDetailVo.class);

if(vo.getStDate()==null){
Calendar now = Calendar.getInstance();
now.set(Calendar.DAY_OF_MONTH,1);
vo.setStDate(DateHelper.parseToString(now.getTime(),DateHelper.yyyyMMdd));
}

if(vo.getEdDate()==null){
Calendar end = Calendar.getInstance();
end.add(Calendar.DAY_OF_MONTH,1);
end.add(Calendar.DAY_OF_MONTH,-1);
vo.setEdDate(DateHelper.parseToString(end.getTime(),DateHelper.yyyyMMdd));
}

PageResult pageObj = manager.selectTouristExpenditureList(vo);

response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-disposition","attachment;filename=expenditure("+vo.getStDate()+"-"+vo.getEdDate()+").xls"); 

EptManager eptManager = new EptManager();

vo.setIoType(1);
BigDecimal outTotal = eptManager.getOutTotal(vo);

vo.setIoType(2);
BigDecimal inTotal = eptManager.getOutTotal(vo);


TouristDetailVo lastMonth = new TouristDetailVo();
Calendar rightNow = Calendar.getInstance();
if(vo.getStDate()!=null&&vo.getStDate().trim().length()>0){
System.out.println(vo.getStDate());
rightNow.setTime(DateHelper.parseToDate(vo.getStDate(),DateHelper.yyyyMMdd));
}
rightNow.set(Calendar.DAY_OF_MONTH,1);
rightNow.add(Calendar.DAY_OF_MONTH,-1);
lastMonth.setEdDate(DateHelper.parseToString(rightNow.getTime(),DateHelper.yyyyMMdd));


//rightNow.set(Calendar.DAY_OF_MONTH,1);
//lastMonth.setStDate(DateHelper.parseToString(rightNow.getTime(),DateHelper.yyyyMMdd));

System.out.println(lastMonth);
lastMonth.setIoType(1);
BigDecimal lastOutTotal = eptManager.getOutTotal(lastMonth);

lastMonth.setIoType(2);
BigDecimal lastInTotal = eptManager.getOutTotal(lastMonth);

BigDecimal yuer = new BigDecimal(0);
BigDecimal zero = new BigDecimal(0);

if(inTotal!=null){
yuer = yuer.add(inTotal);
}

if(outTotal!=null){
yuer = yuer.subtract(outTotal);
}

if(lastInTotal!=null){
yuer = yuer.add(lastInTotal);
}

if(lastOutTotal!=null){
yuer = yuer.subtract(lastOutTotal);
}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'expenditureImport.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <table cellspacing="0" cellpadding="0" border=1 width=100%>
       <tr class="tabHead">
		<td width="40" bgcolor="#FFFF00" nowrap=nowrap>项次</td>
		<td nowrap=nowrap bgcolor="#FFFF00">支出项名称</td>
		<td width="80" bgcolor="#FFFF00" nowrap=nowrap>支出类型</td>
		<td width="80" bgcolor="#FFFF00" nowrap=nowrap>使用者姓名</td>
		<td width="80" bgcolor="#FFFF00" nowrap=nowrap>支出金额</td>
		<td width="70" bgcolor="#FFFF00" nowrap=nowrap>支出日期</td>
		<td width="290" bgcolor="#FFFF00" nowrap=nowrap>支出说明</td>
		<td width="70" bgcolor="#FFFF00" nowrap=nowrap>创建日期</td>
	  </tr>
                           <%
							 int i=0;
							   for(Object obj : pageObj.getPageList()){
							   i++;
							     TouristExpenditure detail = (TouristExpenditure)obj;
							  %>
							<tr class='<%=i%2==0?"list2":"list1"%>'>
								<td class="centerAlign"><%=i%></td>
								<td class="centerAlign"><%=detail.getExpenditureName()%></td>
								<td class="centerAlign"><%=detail.getExpenditureType()%></td>
								<td class="centerAlign"><%=detail.getGuideName() %></td>
								<td class="centerAlign"><%=detail.getExpenditureAmount()==null?"":detail.getExpenditureAmount().setScale(2,BigDecimal.ROUND_HALF_UP)%></td>
								<td class="centerAlign"><%=detail.getExpenditureDate()==null?"":DateHelper.parseToString(detail.getExpenditureDate(),DateHelper.yyyyMMdd)%></td>
								<td class="centerAlign"><%=detail.getExpenditureDesc()==null?"":detail.getExpenditureDesc()%></td>
								<td><%=detail.getExpenditureCreateDate()==null?"":DateHelper.parseToString(detail.getExpenditureCreateDate(),DateHelper.yyyyMMdd)%></td>
							</tr>
							<%
							}
							 %>
                           <tr align="center" bgcolor="lightgreen">
								<td nowrap=nowrap align="right" colspan="8">
								之前累积余额：<a href="expenditure.jsp?stDate=<%=lastMonth.getStDate()==null?"":lastMonth.getStDate()%>&edDate=<%=lastMonth.getEdDate()==null?"":lastMonth.getEdDate()%>" target="_blank"><font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: <%=lastInTotal!=null&&lastOutTotal!=null&&lastInTotal.compareTo(lastOutTotal)>0?"green":"red" %>; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷">
								<%if(lastInTotal!=null&&lastOutTotal!=null){
								    out.print(lastInTotal.subtract(lastOutTotal).setScale(2,BigDecimal.ROUND_HALF_UP));
								}else if(lastInTotal!=null){
								    out.print(lastInTotal.setScale(2,BigDecimal.ROUND_HALF_UP));
								}else if(lastOutTotal!=null){
								    out.print("-"+lastOutTotal.setScale(2,BigDecimal.ROUND_HALF_UP));
								}else
								    out.print("0.00"); %></font></a>&nbsp;&nbsp;&nbsp;&nbsp;
								
								查询支出总计:<a href="expenditure.jsp?stDate=<%=vo.getStDate()==null?"":vo.getStDate()%>&edDate=<%=vo.getEdDate()==null?"":vo.getEdDate()%>&ioType=<%=vo.getIoType()==null?"":vo.getIoType()%>" target="_blank"><font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: red; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=outTotal==null?"0.00":outTotal%></font></a>&nbsp;&nbsp;&nbsp;&nbsp; 
								查询收入总计:<a href="expenditure.jsp?stDate=<%=vo.getStDate()==null?"":vo.getStDate()%>&edDate=<%=vo.getEdDate()==null?"":vo.getEdDate()%>&ioType=<%=vo.getIoType()==null?"":vo.getIoType()%>" target="_blank"><font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: green; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=inTotal==null?"0.00":inTotal%></font></a>&nbsp;&nbsp;&nbsp;&nbsp; 
								余额:<font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: <%=yuer.compareTo(zero)>0?"green":"red" %>; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷">
								<%if(yuer!=null){
								    out.print(yuer.setScale(2,BigDecimal.ROUND_HALF_UP));
								}else
								    out.print("0.00"); %></font>
								</td>
							</tr>
    
    </table>
  </body>
</html>
